<?php


namespace app\admin\system\controller;


use app\common\service\ConfigService;
use support\exception\BadException;

class ConfigController extends BaseController
{
    public function getConfig()
    {
        $key = input('key');
        if (!$key) {
            throw new BadException("参数异常");
        }
        return $this->success(ConfigService::getConfig($key)?:new \stdClass());
    }

    public function getData()
    {
        $key = input('key');
        if (!$key) {
            throw new BadException("参数异常");
        }
        return $this->success(ConfigService::getData($key));
    }

    public function setConfig()
    {
        $key = input('key');
        $value = input('value');

        if (!$key) {
            throw new BadException("参数异常");
        }
        ConfigService::setConfig($key, $value);
        return $this->success();
    }
}